package lesson12;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class DouDiZhuGame {
    private ArrayList<Puke> pukes = new ArrayList();
    private String [] types = {"黑桃","红心","梅花","方块"};
    private String [] points = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
    public DouDiZhuGame(){
        init();
        xipai();
        send();
    }

    /**
     * 将54张扑克牌初始化并放在对应的集合里面
     */
    public void init(){
        for(int i = 0;i < types.length;i++){
            for(int j = 0;j < points.length;j++){
                pukes.add(new Puke(points[j],types[i],j,i));
            }
        }
        pukes.add(new Puke("大王","",14,0));
        pukes.add(new Puke("小王","",13,0));

    }

    /**
     * 洗牌
     */
    public void xipai(){
        Collections.shuffle(pukes);
    }

    /**
     * 发牌
     */
    public void send(){
        List playerOne = pukes.subList(0,17);
        List playerTwo = pukes.subList(17,34);
        List playerThree = pukes.subList(34,51);
        List dipai = pukes.subList(51,54);

        sort(playerOne);
        sort(playerTwo);
        sort(playerThree);

        System.out.println("玩家一：" + playerOne);
        System.out.println("玩家二：" + playerTwo);
        System.out.println("玩家三：" + playerThree);
        System.out.println("底牌：" + dipai);
    }
    public void sort(List list){
        Collections.sort(list,new Comparator<Puke>(){
            @Override
            public int compare(Puke o1, Puke o2) {
                if(o2.getPointValue() == o1.getPointValue()){
                    return o1.getTypeValue() - o2.getTypeValue();
                }else{
                    return o2.getPointValue() - o1.getPointValue();
                }

            }

        });
    }

    public static void main(String[] args) {
        new DouDiZhuGame();

    }
}
